package org.component.integration.samples.controller;

import java.util.Map;
import java.util.UUID;

import org.easyframework.core.entity.ResponseResult;
import org.easyframework.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * @ClassName: RedisController
 * @Description: Redis控制器类
 * @author: daiw
 * @date: 2019年10月15日 下午2:50:54
 */
@RestController
@RequestMapping("redis")
public class RedisController {

	@Autowired
	private RedisUtil redisUtil;

	@RequestMapping("add")
	@ResponseBody
	public ResponseResult add(@RequestBody Map<String, String> param) {
		String key = UUID.randomUUID().toString();
		redisUtil.setString(key, param.get("value"));
		return ResponseResult.getInst(ResponseResult.SUCCESS, key);
	}

	@RequestMapping("query")
	@ResponseBody
	public ResponseResult query(@RequestBody Map<String, String> param) {
		String value = redisUtil.getString(param.get("key"));
		return ResponseResult.getInst(ResponseResult.SUCCESS, value);
	}

	@RequestMapping("remove")
	@ResponseBody
	public ResponseResult remove(@RequestBody Map<String, String> param) {
		return ResponseResult.getInst(ResponseResult.SUCCESS, redisUtil.del(param.get("key")));
	}
}
